/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2023-08-14 16:54:06
 * @LastEditors: TT
 * @LastEditTime: 2023-10-31 16:04:23
 */

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:hzy_project_template/assets/assets.dart';
import 'package:hzy_project_template/commpontents/commpontents_index.dart';
import 'package:hzy_project_template/config/config_index.dart';
import 'package:hzy_project_template/utils/utils_index.dart';

import '../routers/routers_index.dart';

class LoginCompontentS {
  /// 创建通用登录页头部页面
  static configLoginHeaderWidget() {
    Widget body = Image.asset(
      Assets.exampleLolJie,
    );

    body = ClipRRect(
      borderRadius: BorderRadius.circular(8.r),
      child: body,
    );
    body = Padding(
      padding: EdgeInsets.only(
        top: SizeMacro.navh + 40.w,
        left: 20.w,
        right: 20.w,
        bottom: 60.w,
      ),
      child: body,
    );
    return body;
  }

  /// 创建通用登录按钮
  static configLoginBtnWidget({
    required TapCallback tapCallback,
    String? text,
    bool isCanTap = true,
  }) {
    Widget body = configOnlyTextBtnWidget(
      text: text ?? LaunchIdConfig.login.tr,
      tapCall: tapCallback,
      height: 48.w,
      isCanTap: isCanTap,
    );
    return body;
  }

  /// 创建底部
  /// 工具按钮
  static configBottomOtherLogin({
    int type = 0,
    String? account,
  }) {
    configBottomOtherLoginBtnWidget({
      required String text,
    }) {
      Widget body = HzyBtnWidget(
        text: text,
        fontColor: HzyNormalColorS.cola6a6a6,
        fontSize: 14.sp,
        padding: EdgeInsets.symmetric(
          horizontal: 10.w,
        ),
        tapCall: () {
          String router = "";
          if (text == NoteLauncIdConfig.forget.tr) {
            router = NoteLoginModuleRouterS.forget;
          } else if (text == NoteLauncIdConfig.switchAccount.tr) {
            router = NoteLoginModuleRouterS.accountLogin;
          } else if (text == NoteLauncIdConfig.register.tr) {
            router = NoteLoginModuleRouterS.register;
          }
          currentToPage(
            name: router,
            arguments: account,
          );
        },
      );
      return body;
    }

    List<String> titleList = type == 0
        ? [
            NoteLauncIdConfig.forget.tr,
            NoteLauncIdConfig.switchAccount.tr,
            NoteLauncIdConfig.register.tr,
          ]
        : [
            NoteLauncIdConfig.forget.tr,
            NoteLauncIdConfig.register.tr,
          ];
    List<Widget> children = [];
    for (var i = 0; i < titleList.length; i++) {
      children.add(
        configBottomOtherLoginBtnWidget(
          text: titleList[i],
        ),
      );
      if (i != titleList.length - 1) {
        children.add(
          Container(
            width: 1,
            padding: EdgeInsets.only(top: 5.w, bottom: 5.w),
            decoration: BoxDecoration(
              color: HzyCommonColor().colplacetextcolor,
            ),
          ),
        );
      }
    }
    Widget body = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: children,
    );
    body = type == 3 ? Container() : body;
    return body;
  }

  /// 提醒用户 同意协议
  static configRemindUserToAgree({
    required BuildContext context,
  }) async {
    bool yorn = await showPopDiaLogWidget(
      context: context,
      title: "用户登录指引协议",
      msgWidget: RichText(
        text: TextSpan(
          children: [
            TextSpan(
              text: "阅读并同意",
              style: HzyTextStyle.fontMedium(
                size: Dimens.font_14,
                color: loginNoAgreementPopColor,
              ),
            ),
            TextSpan(
              text: "《用户登录指引协议》",
              style: HzyTextStyle.fontBold(
                size: Dimens.font_14,
                color: loginBlackColor,
              ),
              recognizer: TapGestureRecognizer()..onTap = () => (),
            ),
            TextSpan(
              text: "${NoteLauncIdConfig.appName.tr}将严格保护你的个人信息安全",
              style: HzyTextStyle.fontMedium(
                size: Dimens.font_14,
                color: loginNoAgreementPopColor,
              ),
            ),
          ],
        ),
      ),
    );

    return yorn;
  }

  static configOnceLoginPop() async {
    var yorn = await showPopDiaLogWidget<bool>(
      context: Get.context!,
      cannerMsg: LaunchIdConfig.canner.tr,
      sureMsg: LaunchIdConfig.agree.tr,
      msg: LaunchIdConfig.oneLoginPopMsg.tr,
      msgFontSize: 16,
    );
    return yorn;
  }
}
